// pages/home/word/word.js

const app = getApp()
var base_url = app.globalData.url
var clientHeight = app.globalData.clientHeight
Page({

  /**
   * 页面的初始数据
   */
  data: {
    vbg1:'#02C7A3',
    vbg2:'#ededed',
    vc1:'white',
    vc2: '#999999',
    vis1:'block',
    vis2:'none',
    height: clientHeight
  },

  video2:function(){
    var that = this
    that.setData({
      vbg1: '#ededed',
      vbg2: '#02C7A3',
      vc1: '#999999',
      vc2: '#ffffff',
      vis1: 'none',
      vis2: 'block'
      // videopath_hard: res["data"][0]['videopath_soft1']
    })
  },
  video1: function () {
    var that = this
    that.setData({
      vbg1: '#02C7A3',
      vbg2: '#ededed',
      vc1: 'white',
      vc2: '#02C7A3',
      // videopath_hard: res['data'][0]['videopath_hard'],
      vis1: 'block',
      vis2: 'none'
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getStorage({
      key: 'wordDatas',
      success: function (res) {
        console.log(res["data"])
        that.setData({
          wordDatas:res["data"],
          wordName: res["data"][0]["wordName"],
          pinyin: res["data"][0]["pinyin"],
          struct: res["data"][0]["struct"],
          rewording: res["data"][0]["rewording"],
          videopath_hard: res['data'][0]['videopath_hard'],
          videopath_soft1: res["data"][0]['videopath_soft1'],
          bishupath: res["data"][0]['bishupath'],
          wordPath: res["data"][0]['wordPath']
        })
        if (res['data'][0]['videopath_hard'] == ''){
          that.setData({
            showVideo:false
          })
        }else{
          that.setData({
            showVideo: true
          })
        }
        var otherWords = [];
        for(var i=1;i<res["data"].length;i++){
          otherWords.push(res["data"][i])
        }
        that.setData({
          otherWords:otherWords
        })
      },
    })

  },
    

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  changeWord:function(res){
    var that = this
    var videoContextPrev = wx.createVideoContext('myVideo')
    videoContextPrev.pause()
    var index = res.currentTarget.dataset["index"]
    that.setData({
      wordName: that.data.wordDatas[index]["wordName"],
      pinyin: that.data.wordDatas[index]["pinyin"],
      struct: that.data.wordDatas[index]["struct"],
      rewording: that.data.wordDatas[index]["rewording"],
      videopath_hard: that.data.wordDatas[index]["videopath_hard"],
      videopath_soft1: that.data.wordDatas[index]['videopath_soft1'],
      bishupath: that.data.wordDatas[index]['bishupath'],
      wordPath: that.data.wordDatas[index]['wordPath']
    })
  }
})